package com.zhbr.mvp.ui.activity;

import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.zhbr.R;
import com.zhbr.common.StringUtils;
import com.zhbr.entity.Account;
import com.zhbr.mvp.base.view.BaseActivity;
import com.zhbr.mvp.contract.RegisterContract;
import com.zhbr.mvp.presenter.RegisterPresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class RegisterActivity extends BaseActivity<RegisterPresenter> implements RegisterContract.View{

    @BindView(R.id.et_nickname)
    EditText et_nickname;
    @BindView(R.id.et_phone)
    EditText et_phone;
    @BindView(R.id.et_password1)
    EditText et_password1;
    @BindView(R.id.et_password2)
    EditText et_password2;



    @Override
    protected RegisterPresenter createPresenter() {
        return new RegisterPresenter();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.btn_register)
    public void onViewClick(View view){
        showToast("点击了按钮！");
        String nickname = et_nickname.getText().toString();
        String phone= et_phone.getText().toString();
        String password1= et_password1.getText().toString();
        String password2= et_password2.getText().toString();
        if (StringUtils.isEmpty(nickname)){
            showToast("昵称不能为空");
            return;
        }
        if (StringUtils.isEmpty(phone)){
            showToast("手机号码不能为空");
            return;
        }
        if (StringUtils.isEmpty(password1)){
            showToast("密码不能为空");
            return;
        }
        if (!password1.equals(password2)){
            showToast("输入密码不一致");
            return;
        }
        mPresenter.register(nickname,phone,password1);
    }

    @Override
    public void onRegisterSuccess(Account data) {
        showToast("注册成功,请登录");
        navigateTo(LoginActivity.class);
    }

    @Override
    public void onRegisterFail(Throwable ex, String code, String msg) {
        Log.d("注册失败",code);
    }
}